package modules.componentpanel
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	import mx.collections.XMLListCollection;

	import org.spicefactory.lib.xml.XmlObjectMapper;
	import org.spicefactory.lib.xml.mapper.XmlObjectMappings;

	import vos.HTMLCategoryVO;
	import vos.HTMLItemVO;

//	[AsyncInit]
	public class ComponentsPanelPM extends EventDispatcher
	{
		public function ComponentsPanelPM()
		{
			loadXMLConfig();
		}

		public var categories:Vector.<HTMLCategoryVO>;

		private function loadXMLConfig():void
		{
			var xmlData:XML=GlobalConfig.HTML_ITEMS_XML;
			var list:XMLList=xmlData.children();
			var collection:XMLListCollection=new XMLListCollection(list);
			var length:int=collection.length;
			categories=new Vector.<HTMLCategoryVO>();
			for (var i:int=0; i < length; i++)
			{
				var xml:XML=collection[i];
				var mapper:XmlObjectMapper=XmlObjectMappings.forUnqualifiedElements().withRootElement(HTMLCategoryVO).mappedClasses(HTMLItemVO).build();
				var category:HTMLCategoryVO=mapper.mapToObject(xml) as HTMLCategoryVO;
//				trace("category: " + category.name);
				categories.push(category);
			}
//			dispatchEvent(new Event(Event.COMPLETE));
			//this will be finished before other injection
		}

	}
}
